package cn.ffcs.uec.staffAndOutStaff.component;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zul.Bandbox;

import cn.ffcs.uec.staffAndOutStaff.component.bean.StaffAndOutStaffBandboxExtBean;
import cn.ffcs.uec.staffAndOutStaff.vo.StaffAndOutStaff;
import lombok.Getter;

@Controller
@Scope("prototype")
public class StaffAndOutStaffBandboxExt extends Bandbox implements IdSpace {

	private static final long serialVersionUID = 6521012317839335243L;

	private static final String ZUL = "/pages_nmg/staffAndOutStaff/comp/staffAndOutStaff_bandbox_ext.zul";

	private StaffAndOutStaffBandboxExtBean bean = new StaffAndOutStaffBandboxExtBean();

	private StaffAndOutStaff staffAndOutStaff;

	@Getter
	private StaffAndOutStaffListbox staffAndOutStaffListbox;

	/**
	 * 初始化
	 */
	public StaffAndOutStaffBandboxExt() {
		Executions.createComponents(ZUL, this, null);
		Components.wireVariables(this, bean);
		Components.addForwards(this, this, '$');
		// 1、先获取控件
		staffAndOutStaffListbox = (StaffAndOutStaffListbox) this.getFellow("staffAndOutStaffListbox");
		// 2、中转：转换监听的事件与处理事件的方法名
		staffAndOutStaffListbox.addForward("onSelectStaffAndOutStaff", this, "onSelectStaffAndOutStaffResponse");
	}

	/**
	 * 监听事件
	 * 
	 * @param event
	 */
	public void onSelectStaffAndOutStaffResponse(final ForwardEvent event) {
		staffAndOutStaff = (StaffAndOutStaff) event.getOrigin().getData();
		if (null != staffAndOutStaff) {
			setValue(staffAndOutStaff.getStaffName());
			this.close();
			Events.postEvent("onStaffAndOutStaffEditSelected", this, staffAndOutStaff);
		}
	}

	/**
	 * 点击”确认“按钮事件
	 */
	public void onClick$okButton() {
		this.close();
	}

	/**
	 * 点击“取消”按钮事件
	 */
	public void onClick$cancelButton() {
		this.close();
	}
}
